using System;
using Deepcode.Flux.Core.Systems.Security;

namespace Deepcode.Flux.Core.Services.Configuration
{
	/// <summary>
	/// Implements a BaseCachedConfigurationFile class that represents
	/// Flux.config. The file is cached for 24 hours, or until a change 
	/// to the file.
	/// </summary>
	public class FluxConfig : BaseCachedConfigurationFile
	{
		protected override string CacheKey{ get{ return "Flux.CONFIG"; }}
		protected override int CacheTimeHours{ get{ return 24; }}
		protected override string FileName{ get{ return "~/Settings/Flux.Config"; }}

		public static FluxAuthenticationMode Authentication
		{
			get
			{
				string auth = Key("Authentication");
				if( auth == "WINDOWS" ) return FluxAuthenticationMode.WINDOWS;
				return FluxAuthenticationMode.FORMS;
			}
		}

		public static string ServerDSN{		get{ return Key("ServerDSN"); }}
		public static string MainDSN{		get{ return Key("MainDSN"); }}
		public static string MailServer{	get{ return Key("MailServer"); }}
		public static string MailUsername { get { return Key("MailUsername"); } }
		public static string MailPassword { get { return Key("MailPassword"); } }
		public static string SystemEmail { get { return Key("SystemEmail"); } }
		public static string ClientName{	get{ return Key("ClientName");  }}
		public static bool EnableInProcSchedule { get { return (Key("EnableInProcSchedule") == "true"); } }

		// Implement a static utility to quickly obtain key values
		public static string Key(string key)
		{
			FluxConfig tc = new FluxConfig();
			return tc[key];
		}
	}
}
